<template>
  <el-form ref="form" :model="form" label-width="90px" class="kxz-callLog__form--back">
    <h3>详细信息</h3>
    <el-form-item label="标题（唯一）:">
      <el-input v-model="form.title" placeholder="请输入标题"></el-input>
    </el-form-item>
    <el-form-item label="内容:">
      <el-input type="textarea" v-model="form.content" :maxlength="300" placeholder="请输入通话内容(限制在300字以内)"></el-input>
    </el-form-item>
    <el-form-item label="是否可用:">
      <el-select v-model="form.isUse.selVal" placeholder="请选择活动区域">
        <el-option v-for="(item,index) in form.isUse.opts" :key="index" label="item.label" value="item.value"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="handleSubmit">提交</el-button>
      <el-button @click="handleReset">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>

export default {
  name: 'add-mobileMsg',
  data() {
    return {
      form: {
        title:'',
        content:'',
        isUse: {
          selVal:'',
          opts:[
            {
              value:'1',
              label:'可用'
            }
          ]
        }
      }
    }
  },
  methods:{
    handleSave() {
      const form = this.form
      if (form.title === ''){
        this.$warn('请选择标题')
        return
      }
      if (form.content === ''){
        this.$warn('请填写内容')
        return
      }
      if (form.isUse.selVal === ''){
        this.$warn('请选择是否可用')
        return
      }
      // this.postBack()
    },
    handleReset(){
      this.form = {
        title:'',
        content:'',
        isUse: {
          selVal:'',
        }
      }
    },
    async postBack(){
      // 添加回访计划参数有问题
      try{
        const {sessionId} = this.$store.getters.getUserInfo
        const {mobile, telMsg} = this.$store.getters.callMsg
        let {date,content} = this.form
        date = dateFormat(date, 'YYYY-MM-DD HH:mm:ss')
        // const {cU_ser,dh} = this.$store.getters.telMsg
        const {cU_ser,dh} = telMsg
        const {data} = await this.$get(this,{
          api:'ajaxapi/addHfjl.do',
          data:{
            userName:cU_ser,
            sessionId,
            tel: mobile,
            hftime:date,
            beizhu:content,
            danhaoid:dh,
          }
        })
        if(data.state === 0 && data.content === true){
          this.$toast({
            message:'添加成功'
          })
          this.form = {
            date:'',
            content:'',
          }
          return
        }
        this.$warn('添加失败')
      }catch(e){
        this.$warn('系统接口ajaxapi/addHfjl.do报错')
      }
    }
  }
}
</script>